
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 06/07/2011 16:54:37
-- Generated from EDMX file: C:\doc\private\companydic\source\CompanyDic\DataAccess\CompanyDic.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [CompanyDic];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_KindCompany]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[CompanySet] DROP CONSTRAINT [FK_KindCompany];
GO
IF OBJECT_ID(N'[dbo].[FK_CityCompany]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[CompanySet] DROP CONSTRAINT [FK_CityCompany];
GO
IF OBJECT_ID(N'[dbo].[FK_SizeCompany]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[CompanySet] DROP CONSTRAINT [FK_SizeCompany];
GO
IF OBJECT_ID(N'[dbo].[FK_IndustryCompany]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[CompanySet] DROP CONSTRAINT [FK_IndustryCompany];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[CompanySet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[CompanySet];
GO
IF OBJECT_ID(N'[dbo].[KindSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[KindSet];
GO
IF OBJECT_ID(N'[dbo].[SizeSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[SizeSet];
GO
IF OBJECT_ID(N'[dbo].[IndustrySet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[IndustrySet];
GO
IF OBJECT_ID(N'[dbo].[CitySet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[CitySet];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'CompanySet'
CREATE TABLE [dbo].[CompanySet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(100)  NOT NULL,
    [Site] nvarchar(100)  NOT NULL,
    [Address] nvarchar(200)  NOT NULL,
    [Score] int  NOT NULL,
    [Kind_Id] int  NOT NULL,
    [City_Id] int  NOT NULL,
    [Size_Id] int  NOT NULL,
    [Industry_Id] int  NOT NULL
);
GO

-- Creating table 'KindSet'
CREATE TABLE [dbo].[KindSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(20)  NOT NULL
);
GO

-- Creating table 'SizeSet'
CREATE TABLE [dbo].[SizeSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(20)  NOT NULL
);
GO

-- Creating table 'IndustrySet'
CREATE TABLE [dbo].[IndustrySet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(100)  NOT NULL,
    [Code] nvarchar(10)  NOT NULL
);
GO

-- Creating table 'CitySet'
CREATE TABLE [dbo].[CitySet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(20)  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [Id] in table 'CompanySet'
ALTER TABLE [dbo].[CompanySet]
ADD CONSTRAINT [PK_CompanySet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'KindSet'
ALTER TABLE [dbo].[KindSet]
ADD CONSTRAINT [PK_KindSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'SizeSet'
ALTER TABLE [dbo].[SizeSet]
ADD CONSTRAINT [PK_SizeSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'IndustrySet'
ALTER TABLE [dbo].[IndustrySet]
ADD CONSTRAINT [PK_IndustrySet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'CitySet'
ALTER TABLE [dbo].[CitySet]
ADD CONSTRAINT [PK_CitySet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [Kind_Id] in table 'CompanySet'
ALTER TABLE [dbo].[CompanySet]
ADD CONSTRAINT [FK_KindCompany]
    FOREIGN KEY ([Kind_Id])
    REFERENCES [dbo].[KindSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_KindCompany'
CREATE INDEX [IX_FK_KindCompany]
ON [dbo].[CompanySet]
    ([Kind_Id]);
GO

-- Creating foreign key on [City_Id] in table 'CompanySet'
ALTER TABLE [dbo].[CompanySet]
ADD CONSTRAINT [FK_CityCompany]
    FOREIGN KEY ([City_Id])
    REFERENCES [dbo].[CitySet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_CityCompany'
CREATE INDEX [IX_FK_CityCompany]
ON [dbo].[CompanySet]
    ([City_Id]);
GO

-- Creating foreign key on [Size_Id] in table 'CompanySet'
ALTER TABLE [dbo].[CompanySet]
ADD CONSTRAINT [FK_SizeCompany]
    FOREIGN KEY ([Size_Id])
    REFERENCES [dbo].[SizeSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_SizeCompany'
CREATE INDEX [IX_FK_SizeCompany]
ON [dbo].[CompanySet]
    ([Size_Id]);
GO

-- Creating foreign key on [Industry_Id] in table 'CompanySet'
ALTER TABLE [dbo].[CompanySet]
ADD CONSTRAINT [FK_IndustryCompany]
    FOREIGN KEY ([Industry_Id])
    REFERENCES [dbo].[IndustrySet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_IndustryCompany'
CREATE INDEX [IX_FK_IndustryCompany]
ON [dbo].[CompanySet]
    ([Industry_Id]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------